<?php

pm_Context::init('clamav');
$id = pm_Settings::get('clamavId');
$taskId = pm_Settings::get('clamav_freshclam_taskid');
if(isset($taskId)){
    $task = pm_Scheduler::getInstance()->getTaskById($taskId);
    pm_Scheduler::getInstance()->removeTask($task);
}
$taskId2 = pm_Settings::get('clamav_freshclam_taskid2');
if(isset($taskId2)){
    $task2 = pm_Scheduler::getInstance()->getTaskById($taskId2);
    pm_Scheduler::getInstance()->removeTask($task2);
}


$request = <<<APICALL
<ui>
    <delete-custombutton>
        <filter>
            <custombutton-id>$id</custombutton-id>
        </filter>
    </delete-custombutton>
</ui>
APICALL;

try {
    $response = pm_ApiRpc::getService()->call($request);

    $result = $response->ui->{"delete-custombutton"}->result;
    if (true || 'ok' == $result->status) {
        echo "done\n";
        exit(0);
    } else {
        echo "error $result->errcode: $result->errtext\n";
        exit(1);
    }

} catch(PleskAPIParseException $e) {
    echo $e->getMessage() . "\n";
    //exit(1);
}
